package com.platform.toutiao.util.http;

import java.io.IOException;

import com.platform.toutiao.error.TouTiaoErrorException;

import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.ResponseHandler;

public abstract class SimpleGetRequestExecutor<H, P> implements RequestExecutor<String, String> {
	  protected RequestHttp<H, P> requestHttp;

	  public SimpleGetRequestExecutor(RequestHttp<H, P> requestHttp) {
	    this.requestHttp = requestHttp;
	  }

	  @Override
	  public void execute(String uri, String data, ResponseHandler<String> handler) throws TouTiaoErrorException, IOException {
	    handler.handle(this.execute(uri, data));
	  }

	  public static RequestExecutor<String, String> create(RequestHttp requestHttp) {
	    switch (requestHttp.getRequestType()) {
	      case APACHE_HTTP:
	        return new ApacheSimpleGetRequestExecutor(requestHttp);
	      default:
	        throw new IllegalArgumentException("非法请求参数");
	    }
	  }

	  protected String handleResponse(String responseContent) throws TouTiaoErrorException {
	    return responseContent;
	  }
	}
